<?php
    include_once "../lib/DAL/DmHeDaoTao.php";
    class DmHeDaoTaoBLL{
    
    public function __contruct(){
    }
    
    public function __destruct(){
    }
    
    public function setHeDaoTaoBLL($row){
        $dmHeDaoTao = new DmHeDaoTaoDAL();
        $dmHeDaoTao->setDmHeDaoTaoDAL($row['madm_hdt'],$row['ten_hedt'],$row['ten_vt_hedt']);
        return $dmHeDaoTao;
    }
    public function getListHeDaoTao(){
        $sql ="select * from dm_hedaotao";
        $result = mysql_query($sql) or die(mysql_error());
        $arr_hdt = array();
        while($row = mysql_fetch_array($result)){
            $arr_hdt[] = $this->setHeDaoTaoBLL($row);
        }
        return $arr_hdt;
    }
    public function insertHeDaoTao($hdt){
        $sql ="INSERT INTO dm_hedaotao(madm_hdt,ten_hedt,ten_vt_hedt) 
            VALUES ('".$hdt->getmadm_hdt()."'
                    ,'".$hdt->getten_hedt()."'
                    ,'".$hdt->getten_vt_hedt()."'
            )";
        $result = mysql_query($sql) or die (mysql_error());
        return $result;
    }
    public function updateHeDaoTao($hdt){
        $sql="UPDATE dm_hedaotao
            SET  ten_hedt = '".$hdt->getten_hedt()."' 
                ,ten_vt_hedt = '".$hdt->getten_vt_hedt()."'
            WHERE madm_hdt ='".$hdt->getmadm_hdt()."'";
        $result = mysql_query($sql) or die (mysql_error());
        return $result;
    }
    public function deleteHeDaoTao($madm_hdt){
        $sql="DELETE FROM dm_hedaotao WHERE madm_hdt = '".$madm_hdt."'";
        $result = mysql_query($sql) or die (mysql_error());
        return $result;
    }
    public function getItemHDT($madm_hedt){
        $sql="select * from dm_hedaotao where madm_hdt='".$madm_hedt."'";
        $ex=mysql_query($sql);
        if (mysql_num_rows($ex)){
            $kq =mysql_fetch_array($ex);
            }
        return $kq;
    }
//Phân trang
    public function getPages($where,$offset,$limit){
      $result = mysql_query("SELECT * 
                            FROM dm_hedaotao
                            $where  
                            LIMIT $offset, $limit");
      $arr_hdt= array();
      
      while($row = mysql_fetch_array($result)){
        $arr_hdt[] =  $this->setHeDaoTaoBLL($row);
      }
      return $arr_hdt;
    }
    function paging($totalRecords,$limit,$url,$css){
		$totalPage=ceil($totalRecords/$limit);
		$pager='';
		for($i=1;$i<=$totalPage;$i++){
            $pager.="<a href='$url&p=$i' class='$css'>$i</a>";
		}
		return $pager;
	}
	function buildSearchQueryLike($keyword){    
		$dieukien="";   
		$qse=" OR ";
		$arr = tachChuoi($keyword);	
		foreach($arr as $kw){						
			$dieukien .=" madm_hdt LIKE '%$kw%' OR ten_hedt LIKE '%$kw%'";			
			$dieukien .= $qse;	
							
		}
		$cstr = strlen($qse);
		$dieukien = substr($dieukien,0,-$cstr);		
		return $dieukien;	
		
	}
    function timkiem($where){
        $sql="SELECT madm_hdt, ten_hedt, ten_vt_hedt FROM dm_hedaotao $where";
        $ex=mysql_query($sql);
        if($ex){
            while($row=mysql_fetch_array($ex)){
                $dstk[]=$this->setHeDaoTaoBLL($row);
            }
        }
        return $dstk;
    }
//xoa tat ca
    public function deleteAll(){
        $sql="DELETE FROM dm_hedaotao";
        $result = mysql_query($sql) or die (mysql_error());
        return $result;
    }
 }
?>